package com.project.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.project.entity.Custom;
import com.project.mapper.CustomMapper;
import com.project.service.CustomService;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lovo
 * @since 2023-07-21
 */
@Service
public class CustomServiceImp extends ServiceImpl<CustomMapper, Custom> implements CustomService {

    @Override
    public IPage<Custom> cutByItem(Integer pageNo, String name, String scope) {
        QueryWrapper qw = new QueryWrapper<>();
        if (name != null && name.length() != 0){
            qw.like("c_name",name);
        }
        if (scope != null && scope.length() != 0){
            qw.like("c_scope",scope);
        }
        return this.baseMapper.selectPage(new Page<>(pageNo,3),qw);
    }

    @Override
    public void addCustom(Custom custom) {
      int number = this.baseMapper.findByName(custom.getName());
      if (number == 0){
          this.baseMapper.insert(custom);

      }


    }

    @Override
    public Custom findById(Integer id) {
        return this.baseMapper.selectById(id);
    }

    @Override
    public void updateHeadAndPhone(Integer id, String head, String headPhone) {
      Custom custom = this.baseMapper.selectById(id);
      custom.setHead(head);
      custom.setHeadPhone(headPhone);
      this.baseMapper.updateById(custom);

    }
}

